home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 7 / 007.d81 / pps #16 < prev    next >
Encoding:
Text File  |  1985-01-01  |  1.8 KB  |  95 lines

  1.  
  2.  PEEKs, POKEs, and SYSes -- Part 16
  3.  
  4.           by Jimmy Weiler
  5.  
  6. ======================================
  7. Location:631-640 Hexadecimal:$0277-280
  8. Official Label: KEYD         Type: RAM
  9. Useful BASIC commands: PEEK, POKE
  10. ======================================
  11.  
  12.   KEYD is the keyboard data buffer.
  13.  
  14. When a key is pressed, the ASCII value
  15.  
  16. for that key is stored in 631 + peek
  17.  
  18. (198) and location 198 is incremented.
  19.  
  20.   What this means without the
  21.  
  22. gobbledy-gook is that what you type
  23.  
  24. goes into 631 to 640 in the order you
  25.  
  26. type it and 198 counts the keystrokes.
  27.  
  28.   To see how it works, try something
  29.  
  30. like this:
  31.  
  32. 5 PRINT "DON'T YOU DARE TOUCH DEL!"
  33. 10 FOR C = 631 TO 640
  34. 20 PRINT CHR$(PEEK(C));
  35. 30 NEXT
  36. 40 ?"   ";PEEK(198)
  37. 50 IF PEEK(198)>6 THEN GET K$
  38. 60 GOTO 10
  39.  
  40.   You will see the characters you type
  41.  
  42. filling the buffer.  Every time you
  43.  
  44. GET a character, everything in the
  45.  
  46. buffer will shift left one, and the
  47.  
  48. character that has been in the buffer
  49.  
  50. the longest will be taken out.  This
  51.  
  52. is called a First in-First out (FIFO)
  53.  
  54. buffer.
  55.  
  56.   But you don't have to be satisfied
  57.  
  58. with peeking values out of the buffer.
  59.  
  60. You can poke letters into the buffer
  61.  
  62. and those letters will be processed as
  63.  
  64. input from the keyboard.  LOADSTAR
  65.  
  66. uses this technique to connect all the
  67.  
  68. programs together.  Look at our code
  69.  
  70. to see how we clear the screen, print
  71.  
  72. commands on it, and then poke enough
  73.  
  74. carriage returns into the KEYD buffer
  75.  
  76. to execute the commands on the screen.
  77.  
  78.   Here's a trivial example showing
  79.  
  80. what can be done by poking KEYD.
  81.  
  82. 10 C$="RUN          ":rem command
  83. 20 FOR C = 1 TO 10
  84. 30 POKE C + 630, ASC(MID$(C$,C))
  85. 40 NEXT C :rem put command in buffer
  86. 50 POKE 640,13:rem c/r at end of buf
  87. 60 POKE 198,10:rem 10 chars in buffer
  88. 70 PRINT "I just ran again."
  89.  
  90.   Every time the program ends it re-
  91.  
  92. runs itself.
  93.  
  94. --------------------------------------
  95.